﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Clandestine.Battle
{
    public class StatusLine
    {
        public Player Player;
        public TextSprite Name;
        public TextSprite HP;
        public TextSprite MP;

        private const string hpStr = "HP {0}/{1}";
        private const string mpStr = "MP {0}/{1}";

        public StatusLine(Player player, Point origin)
        {
            this.Player = player;
            this.Name = Fonts.Default2.DrawText(player.Name);
            this.HP = Fonts.Default2.DrawText(hpStr, player.HP, player.MaxHP);
            this.MP = Fonts.Default2.DrawText(mpStr, player.MP, player.MaxMP);
            player.OnStatsChange += new CombatantStatsChange(statsChangeHandler);
            updateColour();

            // Position
            Name.Position = new Point(origin.X + 2, origin.Y);
            HP.Position = new Point(origin.X + 170, origin.Y);
            MP.Position = new Point(origin.X + 330, origin.Y);
        }

        private void statsChangeHandler()
        {
            this.HP.Text = String.Format(hpStr, Player.HP, Player.MaxHP);
            this.MP.Text = String.Format(mpStr, Player.MP, Player.MaxMP);
            updateColour();
        }

        private void updateColour()
        {
            if (((float)Player.HP / (float)Player.MaxHP) < 0.15f)
                this.HP.Color = new GLColor(1, 0, 0, 1);
            else
                this.HP.Color = new GLColor(1, 1, 1, 1);
        }

        public void Dispose()
        {
            Player.Dispose();
            HP.Dispose();
            MP.Dispose();
        }
    }
}
